package com.ruoyi.fpa.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.fpa.domain.GenReference;
import com.ruoyi.fpa.service.IGenReferenceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 外键Controller
 * 
 * @author koradji@116.com
 * @date 2023-09-17
 */
@RestController
@RequestMapping("/fpa/reference")
public class GenReferenceController extends BaseController
{
    @Autowired
    private IGenReferenceService genReferenceService;

    /**
     * 查询外键列表
     */
    @PreAuthorize("@ss.hasPermi('fpa:reference:list')")
    @GetMapping("/list")
    public TableDataInfo list(GenReference genReference)
    {
        startPage();
        List<GenReference> list = genReferenceService.selectGenReferenceList(genReference);
        return getDataTable(list);
    }

    /**
     * 导出外键列表
     */
    @PreAuthorize("@ss.hasPermi('fpa:reference:export')")
    @Log(title = "外键", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GenReference genReference)
    {
        List<GenReference> list = genReferenceService.selectGenReferenceList(genReference);
        ExcelUtil<GenReference> util = new ExcelUtil<GenReference>(GenReference.class);
        util.exportExcel(response, list, "外键数据");
    }

    /**
     * 获取外键详细信息
     */
    @PreAuthorize("@ss.hasPermi('fpa:reference:query')")
    @GetMapping(value = "/{referenceId}")
    public AjaxResult getInfo(@PathVariable("referenceId") Long referenceId)
    {
        return success(genReferenceService.selectGenReferenceByReferenceId(referenceId));
    }

    /**
     * 新增外键
     */
    @PreAuthorize("@ss.hasPermi('fpa:reference:add')")
    @Log(title = "外键", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GenReference genReference)
    {
        return toAjax(genReferenceService.insertGenReference(genReference));
    }

    /**
     * 修改外键
     */
    @PreAuthorize("@ss.hasPermi('fpa:reference:edit')")
    @Log(title = "外键", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GenReference genReference)
    {
        return toAjax(genReferenceService.updateGenReference(genReference));
    }

    /**
     * 删除外键
     */
    @PreAuthorize("@ss.hasPermi('fpa:reference:remove')")
    @Log(title = "外键", businessType = BusinessType.DELETE)
	@DeleteMapping("/{referenceIds}")
    public AjaxResult remove(@PathVariable Long[] referenceIds)
    {
        return toAjax(genReferenceService.deleteGenReferenceByReferenceIds(referenceIds));
    }
}
